package com.itheima.controller;
import com.itheima.pojo.Dish;
import com.itheima.pojo.Result;
import com.itheima.service.impl.DishServiceImpl;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Log4j2
@RestController
@RequestMapping("/dish")
public class DishController {
    @Autowired
    private DishServiceImpl dishServiceImpl;

    /**
     * 添加菜品
     *
     * @param dish
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Dish dish) {
        return dishServiceImpl.add(dish);
    }

    /**
     * 分页查询菜品
     */
    @GetMapping("/page")
    public Result page(String name,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        return dishServiceImpl.page(name, page, pageSize);
    }


    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public Result getid(@PathVariable String id) {
        return dishServiceImpl.getid(id);
    }


    /**
     * 删除
     */
    @DeleteMapping
    public Result delect(String ids) {
        return dishServiceImpl.delect(ids);
    }

    /**
     * 起售停售
     */

    @PostMapping("/status/{status}")
    public Result sta(@PathVariable int status, String ids) {
        return dishServiceImpl.update(status, ids);
    }

    /**
     * 修改
     */
    @PutMapping
    public Result update(@RequestBody Dish dish) {
        return dishServiceImpl.updatee(dish);
    }


    /**
     * 下拉列表
     */
    @GetMapping("/list")
    public Result list(String categoryId) {
  return dishServiceImpl.getByCategoryId(categoryId);
    }
}
